<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText"></block>
			<block slot="content" >奖品列表</block>
		</cu-custom>
		<view class="qui-cells solid-top">
			<view class="qui-cell">
				<view class="cell-hd flex">
					<picker mode="date" fields="month" :value="date" start="2015-09" end="2020-09" @change="DateChange">
						<view class="picker fs26">
							{{date}}
						</view>
					</picker>
					<view class="arrow-r arrow-b"></view>
				</view>
				<view class="cell-bd">
					<view class="fs24 text-black tr">总收入<text class="fs30 ff">￥{{sumTotal.toFixed(2)}}</text></view>
				</view>
			</view>
		</view>
		<view class="qui-cells radius5" style="margin: 15rpx;">
			<navigator :url="urlCalc(item.StatusName,item.ActivityPrizeTypeId,item.Id,item.ActivityId)" class="qui-cell flex-start" v-for="(item,index) in pageSour" :key="item.index">
				<view class="cell-hd">
					<text class="round"></text>
				</view>
				<view class="cell-bd">
					<view>
						<text class="fs28 mr10" >
							<text v-if="item.ActivityPrizeCode=='integral'" v-text="item.PrizeName"></text>
							<text v-if="item.ActivityPrizeCode=='redpacket'" v-text="item.PrizeName"></text>
							<text v-if="item.ActivityPrizeCode=='material'" v-text="item.ProductName"></text>
							<text v-if="item.ActivityPrizeCode=='card'" v-text="item.ProductName"></text>
						</text>
						<text v-if="item.ActivityPrizeTypeId==1" class="fs20 text-muted pl10" style="border-left: 1rpx solid #dedede;">
							<text v-if="item.Status==2">已发放微信个人钱包</text>
						<text v-else>{{item.StatusName}}</text>
						</text>
						<text v-if="item.ActivityPrizeTypeId==2" class="fs20 text-muted pl10" style="border-left: 1rpx solid #dedede;">
							<text v-if="item.Status==2">已发放个人积分钱包</text>
							<text v-else>{{item.StatusName}}</text>
						</text>
							<text v-if="item.ActivityPrizeTypeId==3" class="fs20 text-muted pl10" style="border-left: 1rpx solid #dedede;">{{`${item.StatusName}`}}</text>
								<text v-if="item.ActivityPrizeTypeId==4" class="fs20 text-muted pl10" style="border-left: 1rpx solid #dedede;">{{`${item.StatusName}`}}</text>
					</view>
					<view class="fs20 text-muted" v-text="item.GetCreateTime"></view>
				</view>
				<view class="cell-ft mt15">
					<view class="fs30 ff text-black">
						<text v-if="item.ActivityPrizeCode=='integral'" v-text="'+'+parseInt(item.ResultValue)"></text>
						<text v-if="item.ActivityPrizeCode=='redpacket'" v-text="'+'+item.ResultValue"></text>
						
					</view>
				</view>
			</navigator>
		</view>

	</view>
</template>

<script>
	import tools from 'utils/tools.js';
	import base from 'utils/base.js';
	export default {
		data() {
			return {
				imgurl: this.$imgurl,
				date: `${(new Date()).getFullYear()}-${(new Date()).getMonth()+1}`,
				pageSour: [],
				sumTotal: 0,
				title:'',
				type:0
			}
		},
		mounted() {
			this.lodingInitPage();
		},
		onLoad(options) {
			var _self = this;
			if(options.type)
			{
				_self.type = options.type;
				_self.title = options.title;
			}
			
			
		},
		methods: {
			DateChange(e) {
				this.date = e.detail.value
				this.lodingInitPage();
			},
			//主界面数据展示、列表切换条件 1红包 2积分 3实物 4代金券
			lodingInitPage() {
				uni.showLoading({
					title: '加载中',
					mask: true
				});

				var _this = this;
				//获取用户信息
				let globalData = getApp().globalData;
				let userInfo = globalData.UserInfo;
				var requstData = {
					"UserId": userInfo.UserID,
					"ActivityPrizeType": _this.type,
					"CreaTime": _this.date || null,
					"PageIndex": 0,
					"PageSize": 100
				}

				let params = {
					hideLoading: true,
					type: 'POST',
					url: '/Activity/GetActivityPrizeHistoryListByUserId',
					data: requstData,
					sCallback: function(response) {
						uni.hideLoading();
						if (response.Success) {
							var thisSour = response.Data;
							if ((thisSour || null) == null) return false;

							//遍历汇总数据
							thisSour.forEach(function(item) {
								_this.sumTotal += parseFloat((item.ResultValue || 0))
							});

							_this.pageSour = thisSour;

						} else {
							uni.showToast({
								icon: 'none',
								title: response.Msg
							});
						}
					}
				};
				base.ActivityRequest(params);
			},
		},
		computed:{
			urlCalc(){
				return function(StatusName,ActivityPrizeTypeId,Id,ActivityId){
					if(StatusName=="已发放")
					   return `/pages/my/prizeDetail?ActivityPrizeTypeId=${ActivityPrizeTypeId}&Id=${Id}&ActivityId=${ActivityId}`
					else
					   return "";
				}
			}
		},
	}
</script>

<style lang="scss">
	.arrow-b {
		&:after {
			transform: rotate(135deg);
			margin-left: 10rpx;
			margin-top: -10rpx;
			border-color: #6a6a6a;
		}
	}

	.round {
		width: 12rpx;
		height: 12rpx;
		background-color: #f63535;
		border-radius: 50%;
		display: inline-block;
	}
</style>
